//
//  ZWLContentCell.swift
//  ZWLDY
//
//  Created by zwl on 2016/10/2.
//  Copyright © 2016年 zwl. All rights reserved.
//

import UIKit
import SDWebImage

class ZWLContentCell: UICollectionViewCell {

    @IBOutlet weak var titleLabel: UILabel!
   
    @IBOutlet weak var iconImageView: UIImageView!
    
    @IBOutlet weak var nameLabel: UILabel!

    @IBOutlet weak var onlinelab: UIButton!
    
    // MARK:- 定义模型
    var anchor : AnchorModel? {
        didSet {
            // 0.校验模型是否有值
            guard let anchor = anchor else { return }
            
            // 1.取出在线人数显示的文字
            var onlineStr : String = ""
            if anchor.online >= 10000 {
                onlineStr = "\(Int(anchor.online / 10000))万在线"
            } else {
                onlineStr = "\(anchor.online)在线"
            }
            onlinelab.setTitle(onlineStr, for: .normal)
            
            // 2.昵称的显示
            nameLabel.text = anchor.nickname
            
            // 3.设置封面图片
            guard let iconURL = NSURL(string: anchor.vertical_src) else { return }
            iconImageView.sd_setImage(with: iconURL as URL, placeholderImage: UIImage(named: "Img_default"))
        
            // 4.房间名称
            titleLabel.text = anchor.room_name
        }
    }
}
